package com.weipai.demo.controller;

import java.util.ArrayList;

/**
 * @Author: 赵项阳
 * @Date: 2019/7/10 10:23
 * @Version 1.0
 */
public class demo {
    /**
     * 计算等额本息还款
     *
     * @param principal 贷款总额
     * @param months    贷款期限
     * @param rate      贷款利率
     * @return
     */

        public static String[] calculateEqualPrincipalAndInterest(double principal, int months, double rate) {
            ArrayList<String> data = new ArrayList<String>();
            double monthRate = rate / (100 * 12);//月利率
            double preLoan = (principal * monthRate * Math.pow((1 + monthRate), months)) / (Math.pow((1 + monthRate), months) - 1);//每月还款金额
            double totalMoney = preLoan * months;//还款总额
            double interest = totalMoney - principal;//还款总利息
            data.add(String.valueOf(totalMoney));//还款总额
            data.add(String.valueOf(principal));//贷款总额
            data.add(String.valueOf(interest));//还款总利息
            data.add(String.valueOf(preLoan));//每月还款金额
            data.add(String.valueOf(months));//还款期限
            return data.toArray(new String[data.size()]);
        }


}
